
/**    
 * <p>Copyright： 东软烟草产品研发团队</p>   
 */

package com.jkl.service.project;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import com.jkl.comm.service.FileService;
import com.jkl.dao.project.PJProjectPictureMapper;
import com.jkl.entity.project.po.PJProjectPicture;
import com.jkl.service.project.inter.IPJProjectPictureService;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 123service
 * <p>
 * <p>
 * 123service
 * <p>
 * <p>
 * 变更说明：ji.k 2018年1月17日 123service
 * <p>
 * Date:2018年10月01日
 * 
 * @author ji.k
 * @version 1.0
 */
@Service
@Slf4j
public class PJProjectPictureService implements IPJProjectPictureService {

	@Autowired
	private PJProjectPictureMapper pJProjectPictureMapper;
	
	@Autowired
	private FileService fileService;
	
	public PJProjectPictureMapper getMapper(){
		return this.pJProjectPictureMapper;
	}

	public void addProjectPicture(PJProjectPicture picture) {
		pJProjectPictureMapper.addProjectPicture(picture);
	}

	public void addProjectPicture(int picType,Integer recordId, List<MultipartFile> fileList) {
		if (!CollectionUtils.isEmpty(fileList)) {
			for (int i = 0; i < fileList.size(); i++) {
				MultipartFile file = fileList.get(i);
				String fileUrl = fileService.fileUpload(file);
				PJProjectPicture picture = new PJProjectPicture();
				picture.setPicType(picType).setRecordId(recordId).setPicName(file.getOriginalFilename()).setPicUrl(fileUrl)
						.setSequence(i).setStatus(1);
				pJProjectPictureMapper.addProjectPicture(picture);

			}
		}
	}

	@Override
	public void deletePictureByRecordId(PJProjectPicture deletePicture) {
		pJProjectPictureMapper.deleteByRecordIdAndType(deletePicture);		
	}

	@Override
	public void deleteByEntity(PJProjectPicture picture) {
		pJProjectPictureMapper.delete(picture);
	}

}